<template>
  <div class="base-container">
    <toolBar
      :tableColumnConfig="tableColumnConfig"
      :checkedRow="checkedRow"
      :dataList="dataList"
      :toolBarEditBTN="false"
      :toolBarAddBTN="false"
      :toolBarDelBTN="false"
      @edit="edit"
      @del="del"
    ></toolBar>
    <el-table
      v-loading="tableLoading"
      :data="processData"
      style="width: 100%"
      @selection-change="selectionChangeHandle"
    >
      <el-table-column type="selection" width="55"> </el-table-column>
      <template v-for="(item, index) in cptColumn">
        <el-table-column :key="index" :prop="item.prop" :label="item.label" />
      </template>
      <el-table-column label="操作" fixed="right">
        <template slot-scope="scope">
          <el-popover placement="bottom" :ref="scope.$index">
            <p>你确定要删除该条记录吗?</p>
            <div style="text-align: right; margin: 0">
              <el-button
                size="mini"
                type="text"
                @click="$refs[scope.$index].showPopper = false"
                >取消</el-button
              >
              <el-button
                type="primary"
                size="mini"
                @click="forceOut(scope.row.userUid, scope.$index)"
                >确定</el-button
              >
            </div>
            <el-button slot="reference" size="small">强退</el-button>
          </el-popover>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import toolBar from "@/components/common/toolBar";
import popover from "./component/popover";
import curd from "@/mixins/curd.js";
import { sendJSON } from "@/utils/request";
const CURD = new curd({
  url: "/sys/action/"
});
export default {
  components: { toolBar, popover },
  mixins: [CURD],
  data() {
    return {
      // 列表配置
      tableColumnConfig: [
        { id: 1, label: "用户名", prop: "username", show: true },
        { id: 2, label: "绰号", prop: "nickname", show: true },
        { id: 3, label: "浏览器", prop: "browser", show: true },
        { id: 4, label: "IP", prop: "ip", show: true },
        { id: 5, label: "登录时间", prop: "loginTime", show: true }
      ]
    };
  },
  methods: {
    // 刷新-API
    initData() {
      this.tableLoading = true;
      sendJSON("/sys/monitor/onlineUser/getAll").then(res => {
        console.log(
          "%cMyProject%cline:264%cvar",
          "color:#fff;background:#ee6f57;padding:3px;border-radius:2px",
          "color:#fff;background:#1f3c88;padding:3px;border-radius:2px",
          "color:#fff;background:rgb(251, 178, 23);padding:3px;border-radius:2px",
          res
        );
        this.dataList = res.data;
        this.tableLoading = false;
      });
    },
    // 强退用户
    forceOut(uid, index) {
      console.log(uid, index);
      sendJSON("/sys/monitor/onlineUser/forceOut", uid).then(res => {
        console.log(res);
        // 直接删除源数据
        this.dataList = this.dataList.filter(item => item.userUid != uid);
      this.$refs[index].showPopper = false;
        this.$message.success("强退成功！");
      });
    }
  }
};
</script>

<style lang="scss">
@import "@/styles/base/index.scss";
</style>
